Skip to content

Unified: Support Swift borrow, consume, copy, and unsafe expressions - #23104

Merged
paldepind merged 8 commits into
mainfrom
unified/modified-expr
Nov 16, 2026
Merged

paldepind merged 8 commits into
mainfrom
unified/modified-expr

Conversation

@paldepind

@paldepind paldepind commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Just like how await and try are mapped to unary_expr this PR does the same for borrow, consume, copy, and unsafe expressions.

paldepind and others added 2 commits November 11, 2026 15:30
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8dd55540-3d6b-43a8-873a-7d22380d548f
@paldepind
paldepind force-pushed the unified/modified-expr branch from eca683d to 7862a67 Compare November 11, 2026 14:31
@paldepind paldepind changed the title Unified: Support Swift borrow, consume, copy, and unsafe expressions Unified: Support Swift borrow, consume, copy, and unsafe expressions Nov 11, 2026
@paldepind
paldepind marked this pull request as ready for review November 12, 2026 08:59
@paldepind
paldepind requested a review from a team as a code owner November 12, 2026 08:59
Copilot AI adaptive review requested due to automatic review settings November 12, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Swift unary operators lack operand value propagation in unified data flow, causing flows through borrow, consume, copy, and unsafe to stop at the wrapper and leaving a gap in security analyses.

1 open issue
What changed in this PR

Adds unified Swift extraction support for borrow, consume, copy, and unsafe, representing them as unary expressions like await and try.

Changes:

  • Adds translation rules that preserve each keyword as a prefix operator and translate its operand.
  • Removes the corresponding unsupported-node mappings.
  • Adds a borrow fixture and updates expected output for all four expressions.
File Description
unified/​extractor/​tests/​corpus/​swift/​expressions/​unsafe-expression.output Expects a unary expression wrapping the call.
unified/​extractor/​tests/​corpus/​swift/​expressions/​copy-expression.output Expects a copy unary expression.
unified/​extractor/​tests/​corpus/​swift/​expressions/​consume-expression.output Expects a consume unary expression.
unified/​extractor/​tests/​corpus/​swift/​expressions/​borrow-expression.swift Adds a basic borrow-expression fixture.
unified/​extractor/​tests/​corpus/​swift/​expressions/​borrow-expression.output Records the borrow fixture’s expected syntax trees.
unified/​extractor/​src/​languages/​swift/​swift.rs Adds the four unary-expression translation rules.

Review effort: Balanced (auto)

@paldepind
paldepind requested a review from a team as a code owner November 13, 2026 13:38
@paldepind
paldepind requested an adaptive review from Copilot November 13, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new wrappers propagate value flow but not operand types, causing unannotated declarations to lose inferred receiver types and breaking subsequent member or method resolution.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Propagate operand types through all four copy operators

unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowPluginSwift.qll:75

Value flow now passes through these wrappers, but neither TypeInferencePluginSwift.qll::inferType nor TypeInference.qll::stepLanguageSpecific propagates their operand types. Consequently, an unannotated declaration such as let copied = copy original loses the inferred receiver type needed to resolve subsequent instance member accesses or method calls. Propagate operand types, including generic type paths, through all four operators and add type-inference/member-resolution regression tests.

1 resolved since last review

Review effort: Balanced (dynamic)

paldepind and others added 2 commits November 15, 2026 11:15
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b38cac73-399a-4e08-85f8-1c7c1346896b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b38cac73-399a-4e08-85f8-1c7c1346896b
@paldepind paldepind added the no-change-note-required This PR does not need a change note label Nov 16, 2026
@paldepind

Copy link
Copy Markdown
Contributor Author

I've updated the PR with data flow and type inference adaptations as well.

@paldepind
paldepind requested a review from asgerf November 16, 2026 07:21
paldepind and others added 2 commits November 16, 2026 08:48
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b38cac73-399a-4e08-85f8-1c7c1346896b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b38cac73-399a-4e08-85f8-1c7c1346896b

@hvitved hvitved left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paldepind
paldepind merged commit dd031f5 into main Nov 16, 2026
17 checks passed
@paldepind
paldepind deleted the unified/modified-expr branch November 16, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants